/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.rpgmapper.bo.rules;

import java.util.ArrayList;
import java.util.List;
import org.rpgmapper.bo.Character;
import org.rpgmapper.bo.Stat;

/**
 *
 * @author Nehon
 */
public class CoreRules extends Rule {

    private static CoreRules instance;
    private List<Rule> rules = new ArrayList<Rule>();
    private Rule BMOAltRule = new ModifierRule(Stat.BMO, 0, Stat.BBA, Stat.DexMod, Stat.Size);

    public static CoreRules get() {
        if (instance == null) {
            instance = new CoreRules();
        }
        return instance;
    }

    private CoreRules() {
        rules.add(new ModifierRule(Stat.Ref, 0, Stat.DexMod));
        rules.add(new ModifierRule(Stat.For, 0, Stat.ConMod));
        rules.add(new ModifierRule(Stat.Wil, 0, Stat.WisMod));
        rules.add(new ModifierRule(Stat.Init, 0, Stat.DexMod));

        rules.add(new ModifierRule(Stat.Melee, 0, Stat.BBA, Stat.StrMod, Stat.Size));
        rules.add(new ModifierRule(Stat.Range, 0, Stat.BBA, Stat.DexMod, Stat.Size));
        rules.add(new ModifierRule(Stat.BMO, 0, Stat.BBA, Stat.StrMod, Stat.Size));
        rules.add(new ModifierRule(Stat.AC, 10, Stat.DexMod, Stat.InvSize));
        rules.add(new ModifierRule(Stat.DMD, 10, Stat.BBA, Stat.DexMod, Stat.StrMod, Stat.Size));
    }

    @Override
    public void apply(Character c) {
        c.setBase(Stat.StrMod, Stat.getModifier(c.getBase(Stat.Str)));
        c.setBase(Stat.DexMod, Stat.getModifier(c.getBase(Stat.Dex)));
        c.setBase(Stat.ConMod, Stat.getModifier(c.getBase(Stat.Con)));
        c.setBase(Stat.IntMod, Stat.getModifier(c.getBase(Stat.Int)));
        c.setBase(Stat.WisMod, Stat.getModifier(c.getBase(Stat.Wis)));
        c.setBase(Stat.ChaMod, Stat.getModifier(c.getBase(Stat.Cha)));
        c.setBase(Stat.InvSize, -c.getBase(Stat.Size));


        if (c.get(Stat.Size) < -1) {
            BMOAltRule.apply(c);
        }

        for (Rule rule : rules) {
            rule.apply(c);
        }
    }
}
